var express = require('express'),
    multer = require('multer');

var port = 3006;
var app = express();
var storge = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'uploads')
    },
    filename: function (req, file, cb) {

        console.log('stfile', file)
        // console.log('req', req)

        var fileformat = (file.originalname).split('.');
        // cb(null, file.originalname);
        cb(null, file.fieldname+'-'+Date.now()+'.jpg');
        // cb(null, file.fieldname+'-'+Date.now()+'.'+fileformat[fileformat.length-1]);
    }
})



var upload = multer({storage: storge})
app.use(express.static('./static'));

app.post('/', upload.array('file',20), function (req, res, next) {
    // console.log(req.files);
    res.send('全部上传成功');
})

app.listen(port, ()=> {
    console.log('OK, node server on: ' + port)
})